package com.unionpay.acp.sdk;

import org.apache.commons.lang3.StringUtils;

import cn.demoncat.util.lang.constant.StatusConstant.Common;
import cn.demoncat.util.pay.unionpay.config.UnionpayProperties;
import cn.demoncat.util.pay.unionpay.constant.UnionpayConstant;

/**
 * 配置
 * 
 * @author 银联
 *
 * @since 2016-7-22
 */
public class SDKConfig {
	
	/** API - 前台请求URL. */
	public static String frontRequestUrl;
	/** API - 后台请求URL. */
	public static String backRequestUrl;
	/** API - 单笔查询 */
	public static String singleQueryUrl;
	/** API - 批量交易 */
	public static String batchTransUrl;
	/** API - 文件传输 */
	public static String fileTransUrl;
	/** API - 有卡交易. */
	public static String cardRequestUrl;
	/** API - APP交易 */
	public static String appRequestUrl;
	
	/** 签名证书路径. */
	public static String signCertPath;
	/** 签名证书密码. */
	public static String signCertPwd;
	/** 签名证书类型 */
	public static String signCertType = "PKCS12";
	/** 加密公钥证书路径. */
	public static String encryptCertPath;
	/** 中级证书路径  */
	public static String middleCertPath;
	/** 根证书路径  */
	public static String rootCertPath;
	/** 是否验证验签证书CN  */
	public static boolean ifValidateCNName;
	/** 是否验证https证书：生产环境建议true，如果报错再改成false  */
	public static boolean ifValidateRemoteCert;
	/** 数据签名方法 - RSA  */
	public static String signMethod = "01";
	/** 接口版本  */
	public static String version = "5.1.0";
	
	/** 后台异步通知地址：支付/撤销/退款异步通知，10秒内未返回HTTP-200就间隔重发5次  */
	public static String backUrl;
	/** 前台异步通知地址  */
	public static String frontUrl;
	/** 前台失败通知地址  */
	public static String frontFailUrl;
	
	/**
	 * 初始化银联配置
	 * 
	 * @param pro
	 * 
	 * @author 延晓磊
	 *
	 * @since 2020年3月26日
	 */
	public static void init(UnionpayProperties pro) {
		// 证书
		signCertPath = pro.getSignCertPath().trim();
		signCertPwd = pro.getSignCertPassword().trim();
		encryptCertPath = pro.getEncryptCertPath().trim();
		rootCertPath = pro.getRootCertPath().trim();
		middleCertPath = pro.getMiddleCertPath().trim();
		// 接口
		frontRequestUrl = (Common.isYes(pro.getStatus()) ? UnionpayConstant.Domain.PROD : UnionpayConstant.Domain.TEST) + UnionpayConstant.Api.FRONT_TRANS;
		backRequestUrl = (Common.isYes(pro.getStatus()) ? UnionpayConstant.Domain.PROD : UnionpayConstant.Domain.TEST) + UnionpayConstant.Api.BACK_TRANS;
		singleQueryUrl = (Common.isYes(pro.getStatus()) ? UnionpayConstant.Domain.PROD : UnionpayConstant.Domain.TEST) + UnionpayConstant.Api.QUERY_TRANS;
		fileTransUrl = Common.isYes(pro.getStatus()) ? UnionpayConstant.Domain.PROD_FILE : UnionpayConstant.Domain.TEST_FILE;
		appRequestUrl = (Common.isYes(pro.getStatus()) ? UnionpayConstant.Domain.PROD : UnionpayConstant.Domain.TEST) + UnionpayConstant.Api.APP_TRANS;
		cardRequestUrl = (Common.isYes(pro.getStatus()) ? UnionpayConstant.Domain.PROD : UnionpayConstant.Domain.TEST) + UnionpayConstant.Api.CARD_TRANS;
		batchTransUrl = (Common.isYes(pro.getStatus()) ? UnionpayConstant.Domain.PROD : UnionpayConstant.Domain.TEST) + UnionpayConstant.Api.BATCH_TRANS;
		// 通知
		backUrl = pro.getBackNotifyUrl().trim();
		frontUrl = pro.getFrontNotifyUrl().trim();
		frontFailUrl = StringUtils.trimToNull(pro.getFrontFailNotifyUrl());
		// 其它
		ifValidateCNName = Common.isYes(pro.getStatus());
		ifValidateRemoteCert = Common.isYes(pro.getStatus());
	}


}
